<?php
    session_start();
    if ($_SESSION['login'] == '')
    {
        $currentFile = $_SERVER["PHP_SELF"];
        $parts = Explode('/', $currentFile);
        
        if($parts[count($parts) - 1] != 'login.php' && $parts[count($parts) - 1] != 'contact.php'){
            header('Location: ./login.php');
        }
    }

    // Get and set language
    // Language is not specified in the URI
    if ($_REQUEST['lang'] == null) {
        // No language already in use, so take the browser language
        if($_SESSION['lang'] == null) {
            $language = $_SERVER['HTTP_ACCEPT_LANGUAGE']; 
            $language = $language{0}.$language{1};

            // German
            if($language == 'de')
                $_SESSION['lang'] = 'de';
            // All other languages are set to French
            else                
                $_SESSION['lang'] = 'fr';
        }
    } else
        // Language specified in the URI
        $_SESSION['lang'] = $_REQUEST['lang'];
    
    if($_SESSION['previous_page_register'] == "")
        $_SESSION['previous_page_register'] = './index.php';
    if($_SESSION['previous_page_detailTheme'] == "")
        $_SESSION['previous_page_detailTheme'] = './index.php';
    
    include('translations.php');
?>

<!DOCTYPE html>
<html>       
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1"> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title><?php echo $texts['title_page'][$_SESSION['lang']] ?></title> 
        <link rel="stylesheet" href="jquery/jquery.mobile-1.0.1.min.bis.css" />
        <link rel="stylesheet" href="jquery/photoswipe.css" />
        <script src="jquery/jquery-1.7.1.min.js"></script>
        <script src="jquery/jquery.mobile-1.0.1.min.js"></script>
        <script src="scrollTo/localscroll/jquery.localscroll.js"></script>
	<script src="scrollTo/localscroll/jquery.scrollTo.js"></script>
	<script src="scrollTo/lancement.js"></script>  
        <script type="text/javascript" src="jquery/klass.min.js"/>
        <script src="jquery/jquery.ui.core.js"></script>
        
        <!-- AJOUT DES SCRIPTS POUR L'AFFICHAGE DE LA GALERIE -->
        <SCRIPT type="text/javascript" src="jquery/code.photoswipe.jquery-3.0.4.min.js" />
        
        <script type="text/javascript">
            var month = ['Janvier','Février','Mars','Avril','Mai','Juin',
                'Juillet','Août','Septembre','Octobre','Novembre','Décembre'];
            
            var dayBig = ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'];
            var dayShort = ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'];
            var dayMin = ['Di','Lu','Ma','Me','Je','Ve','Sa'];
            
            $(function(){
                $("#dateFrom").datepicker({ dateFormat : "dd.mm.yy",
                                            prevText: '',
                                            nextText: '',
                                            monthNames: month,
                                            dayNames: dayBig,
                                            dayNamesShort: dayShort,
                                            dayNamesMin: dayMin
                                          });
                $("#dateTo").datepicker({ dateFormat : "dd.mm.yy",
                                          prevText: '',
                                          nextText: '',
                                          monthNames: month,
                                          dayNames: dayBig,
                                          dayNamesShort: dayShort,
                                          dayNamesMin: dayMin
                                      });
            });

        </script>
        
        <script type="text/javascript">
            (function(window, $, PhotoSwipe)
            {
                $(document).ready(function()
                {
                    $("#gallery a").photoSwipe(
                    {
                        enableMouseWheel: false,
                        enableKeyboard: false
                    });
                });
            }(window, window.jQuery, window.Code.PhotoSwipe));
        </script>

    </head> 
    <body>
        <!-- /header -->
        <div data-role="header"  data-theme="b">
            <table width="100%">
                <tr>
                    <!-- Flag icon -->
                    
                        <?php
                        // Select icon to be displayed
                        $flagFR = 'fr';                        
                        $flagDE = 'de';
                        if ($_SESSION['lang'] == 'de')
                            $flag = 'fr';
                        else
                            $flag = 'de';
                        
                        
                        
                        // Get the current URL
                        // Protocol (HTTP or HTTPS)
                        $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') 
                                        === FALSE ? 'http' : 'https';
                        // Host (www.website.com)
                        $host     = $_SERVER['HTTP_HOST'];
                        // URI (/detailTheme.php?theme=1&event=1)
                        $uri      = $_SERVER['REQUEST_URI'];
                        // Complete URL (http://www.website.com/detailTheme.php?theme=1&event=1)
                        $currentUrl = $protocol . '://' . $host . $uri;
                        
                        // Remove the previous lang parameter and set the new one
                        if($_SERVER['QUERY_STRING'] == null){
                            $currentUrlFR = $currentUrl."?lang=".$flagFR;
                            $currentUrlDE = $currentUrl."?lang=".$flagDE;
                        }
                        else 
                            if ($_SERVER['QUERY_STRING'] == "lang=de" || $_SERVER['QUERY_STRING'] == "lang=fr") {
                                $removeLangParam = explode("?lang=", $currentUrl);
                                $currentUrl = $removeLangParam[0];
                                $currentUrlFR = $currentUrl."?lang=".$flagFR;
                                $currentUrlDE = $currentUrl."?lang=".$flagDE;
                            } 
                            else {
                                $removeLangParam = explode("&lang=", $currentUrl);
                                $currentUrl = $removeLangParam[0];
                                $currentUrlFR =$currentUrl."&lang=".$flagFR;
                                $currentUrlDE = $currentUrl."&lang=".$flagDE;
                                //$currentUrl .= "&lang=".$flag;
                            }
                    ?>
                    <th width="40px"><a onclick="javascript:window.location='<?php echo $currentUrlFR ?>';"><img src="picture/flag_fr.png"/></a></th>
                    <th width="40px"><a onclick="javascript:window.location='<?php echo $currentUrlDE ?>';"><img src="picture/flag_de.png"/></a></th>
                    <!-- Valais flag -->
                    <th><span id="logo"><a href="./index.php" rel="external"><img src="jquery/images/logo_valais_OK.png" /></a></span></th>
                    <?php 
                    if ($_SESSION['login'] <> '') {
                        ?>
                    <!-- Logout icon -->
                    <th width="40px"><a href="logout.php"><img src="picture/logout.png" /></a></th>
                    <?php 
                    }
                    ?>
                </tr>
            </table>
        </div>